from fastapi import APIRouter, Query
from services.course import query_all_course, add_course, delete_course_by_id, update_course_by_id
from models.request_model import CreateCourseRequest, UpdateCourseRequest

router = APIRouter()

@router.get("/course")
async def get_all_course(
    week_day: int = Query(None, description="星期几"),
    time: int = Query(None, description="第几节课"),
    name: str = Query(None, description="课程名称"),
    teacher: str = Query(None, description="教师姓名"),
    place: str = Query(None, description="教室")
):
    return await query_all_course(week_day, time, name, teacher, place)

@router.post("/course")
async def create_course(body: CreateCourseRequest):
    return await add_course(
        body.week_day,
        body.time,
        body.name,
        body.teacher,
        body.place
    )

@router.delete("/course/{course_id}")
async def delete_course(course_id: int):
    return await delete_course_by_id(course_id)

@router.put("/course")
async def update_course(body: UpdateCourseRequest):
    return await update_course_by_id(
        body.id,
        body.name,
        body.week_day,
        body.time,
        body.teacher,
        body.place
    )